package com.hsc.yalebao.weight;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.Scroller;

import com.hsc.pcddfivepcdd.R;
import com.hsc.yalebao.base.MainActivity;
import com.hsc.yalebao.base.SplashActivity;
import com.hsc.yalebao.newui.NewMainActivity;
import com.hsc.yalebao.newui.UpNewactivity;
import com.hsc.yalebao.tabIndex.RoomPrimaryActivity;

import java.io.PrintStream;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class SwipeBackLayout extends FrameLayout {
    private static final String TAG = SwipeBackLayout.class.getSimpleName();
    private int downX;
    private int downY;
    public boolean isActivityFinish;
    public boolean isFinish;
    public boolean isSilding;
    private Activity mActivity;
    private View mContentView;
    public Scroller mScroller;
    private Drawable mShadowDrawable;
    private int mTouchSlop;
    private List<ViewPager> mViewPagers = new LinkedList();
    private int tempX;
    private int viewWidth;

    public SwipeBackLayout(Context paramContext, AttributeSet paramAttributeSet) {
        this(paramContext, paramAttributeSet, 0);
    }

    public SwipeBackLayout(Context paramContext, AttributeSet paramAttributeSet, int paramInt) {
        super(paramContext, paramAttributeSet, paramInt);
        this.mTouchSlop = ViewConfiguration.get(paramContext).getScaledTouchSlop();
        this.mScroller = new Scroller(paramContext);
        this.mShadowDrawable = getResources().getDrawable(R.drawable.shadow_left);

    }

    private void getAlLViewPager(List<ViewPager> paramList, ViewGroup paramViewGroup) {
        int i = paramViewGroup.getChildCount();
        int j = 0;
        if (j >= i)
            return;
        View localView = paramViewGroup.getChildAt(j);
        if ((localView instanceof ViewPager))
            paramList.add((ViewPager) localView);
        while (true) {
            j++;
            if ((localView instanceof ViewGroup))
                getAlLViewPager(paramList, (ViewGroup) localView);
            break;
        }
    }

    private ViewPager getTouchViewPager(List<ViewPager> paramList, MotionEvent paramMotionEvent) {
        if ((paramList == null) || (paramList.size() == 0))
            return null;
        Rect localRect = new Rect();
        Iterator localIterator = paramList.iterator();
        ViewPager localViewPager;
        do {
            if (!localIterator.hasNext())
                return null;
            localViewPager = (ViewPager) localIterator.next();
            localViewPager.getHitRect(localRect);
        }
        while (!localRect.contains((int) paramMotionEvent.getX(), (int) paramMotionEvent.getY()));
        return localViewPager;
    }

    private void scrollOrigin() {
        int i = this.mContentView.getScrollX();
        this.mScroller.startScroll(this.mContentView.getScrollX(), 0, -i, 0, Math.abs(i));
        postInvalidate();
    }

    private void scrollRight() {
        int i = this.viewWidth + this.mContentView.getScrollX();
        this.mScroller.startScroll(this.mContentView.getScrollX(), 0, 1 + -i, 0, Math.abs(i));
        postInvalidate();
    }

    private void setContentView(View paramView) {
        this.mContentView = ((View) paramView.getParent());
    }

    public void attachToActivity(Activity paramActivity) {
        if ((paramActivity instanceof MainActivity)) ;
        while (((paramActivity instanceof RoomPrimaryActivity)) || ((paramActivity instanceof NewMainActivity)) || ((paramActivity instanceof SplashActivity)) || ((paramActivity instanceof UpNewactivity)))
            return;
        this.mActivity = paramActivity;
        TypedArray localTypedArray = paramActivity.getTheme().obtainStyledAttributes(new int[]{16842836});
        int i = localTypedArray.getResourceId(0, 0);
        localTypedArray.recycle();
        ViewGroup localViewGroup1 = (ViewGroup) paramActivity.getWindow().getDecorView();
        ViewGroup localViewGroup2 = (ViewGroup) localViewGroup1.getChildAt(0);
        localViewGroup2.setBackgroundResource(i);
        localViewGroup1.removeView(localViewGroup2);
        addView(localViewGroup2);
        setContentView(localViewGroup2);
        localViewGroup1.addView(this);
    }

    public void computeScroll() {
        if (this.mScroller.computeScrollOffset()) {
            this.mContentView.scrollTo(this.mScroller.getCurrX(), this.mScroller.getCurrY());
            postInvalidate();
            if ((this.mScroller.isFinished()) && (this.isFinish)) {
                setActivityFinish(true);
                this.mActivity.finish();
            }
        } else {
            return;
        }
        setActivityFinish(false);
    }

    protected void dispatchDraw(Canvas paramCanvas) {
        super.dispatchDraw(paramCanvas);
        if ((this.mShadowDrawable != null) && (this.mContentView != null)) {
            int i = this.mContentView.getLeft() - this.mShadowDrawable.getIntrinsicWidth();
            int j = i + this.mShadowDrawable.getIntrinsicWidth();
            int k = this.mContentView.getTop();
            int m = this.mContentView.getBottom();
            this.mShadowDrawable.setBounds(i, k, j, m);
            this.mShadowDrawable.draw(paramCanvas);
        }
    }

    public boolean isActivityFinish() {
        return this.isActivityFinish;
    }

    public boolean onInterceptTouchEvent(MotionEvent paramMotionEvent) {

        ViewPager localViewPager = getTouchViewPager(this.mViewPagers, paramMotionEvent);
        LogUtils.i(TAG, "mViewPager = " + localViewPager);
        if ((localViewPager != null) && (localViewPager.getCurrentItem() != 0))
            return super.onInterceptTouchEvent(paramMotionEvent);
        switch (paramMotionEvent.getAction()) {
            case 1:
            default:
            case 0:
            case 2:
        }
        int i;
        do {
            int j = (int) paramMotionEvent.getRawX();
            this.tempX = j;
            this.downX = j;
            this.downY = ((int) paramMotionEvent.getRawY());
            System.out.println("downX:" + this.downX);
            i = (int) paramMotionEvent.getRawX();
            if (this.downX > 100)
                return false;
        }
        while ((i - this.downX <= this.mTouchSlop) || (Math.abs((int) paramMotionEvent.getRawY() - this.downY) >= this.mTouchSlop));
        return true;
    }

    protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
        super.onLayout(paramBoolean, paramInt1, paramInt2, paramInt3, paramInt4);
        if (paramBoolean) {
            this.viewWidth = getWidth();
            getAlLViewPager(this.mViewPagers, this);
            LogUtils.i(TAG, "ViewPager size = " + this.mViewPagers.size());
        }
    }

    public boolean onTouchEvent(MotionEvent paramMotionEvent) {
        switch (paramMotionEvent.getAction()) {
            case 2:
                int i;
                int j;
                do {
                    i = (int) paramMotionEvent.getRawX();
                    j = this.tempX - i;
                    this.tempX = i;
                    if ((i - this.downX > this.mTouchSlop) && (Math.abs((int) paramMotionEvent.getRawY() - this.downY) < this.mTouchSlop))
                        this.isSilding = true;
                }
                while ((i - this.downX < 0) || (!this.isSilding));
                this.mContentView.scrollBy(j, 0);
                return true;
            case 1:
                this.isSilding = false;
                if (this.mContentView.getScrollX() <= -this.viewWidth / 3) {
                    this.isFinish = true;
                    scrollRight();
                    return true;
                }
                scrollOrigin();
                this.isFinish = false;
                return true;
        }
        return false;
    }


    public void setActivityFinish(boolean paramBoolean) {
        this.isActivityFinish = paramBoolean;
    }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.weight.SwipeBackLayout
 * JD-Core Version:    0.6.2
 */